Click here to Skip to main content
15,889,682 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need some ideas on how to delete the first row in a excel file and shift the remaining cells up after that. Any ideas??
Posted

You can view the solution here

Delete an Excel row[^]
 
Share this answer
 
Comments
phantomlakshan 24-May-12 3:09am    
Is there any way i can use less code to do this?
Maciej Los 24-May-12 4:15am    
What you mean "less code"?
You need to create an instance of Excel application, open a document, delete row, close a document...
Maciej Los 24-May-12 4:15am    
Good link, my 5!
Hi, have a try with the following codes:
C#
Excel.Application myApp;
           Excel.Workbook myWorkBook;
           Excel.Worksheet myWorkSheet;
           Excel.Range range;
           myApp = new Excel.Application();
           myWorkBook = myApp.Workbooks.Open("D:\\test.xls", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false   , 0, true, 1, 0);
           myWorkSheet = (Excel.Worksheet)myWorkBook.Worksheets.get_Item(1);
           range = (Excel.Range)myWorkSheet.Application.Rows[1, Type.Missing];
           range.Select();
           range.Delete(Excel.XlDirection.xlUp);
           myWorkBook.Close(true);
           myApp.Quit();

Note using Excel = Microsoft.Office.Interop.Excel; and release the object finally.


The following is a summary of some Excel skills you may use. Please have a check if you would like to.

Summarize C# Control Excel Skills[^]
 
Share this answer
 
v2
Comments
Maciej Los 24-May-12 4:15am    
Good work, my 5!
Pandvi 24-May-12 4:30am    
Thank you. losmac!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900